package game.players;

import game.ball.SoccerBall;
import game.players.states.PlayerState;
import game.scene.MatchScene;
import game.soccerField.SoccerField;

import com.uqbar.vainilla.DeltaState;

import utils.Position;
import utils.Range;

public abstract class SoccerPlayerCPU extends SoccerPlayer {
	
	private int refreshCounter;
	private Position initialPosition;
	private Position relativePosition = new Position(0, 0);
	private Range areaX;
	private Range areaY;

	public SoccerPlayerCPU(double x, double y, Range areaX, Range areaY) {
		super(x, y);
		this.setInitialPosition(new Position(x, y));
		this.setAreaX(areaX);
		this.setAreaY(areaY);
	}
	
	public SoccerPlayerCPU(double x, double y, Range areaX, Range areaY, PlayerState state) {
		super(x, y);
		this.setInitialPosition(new Position(x, y));
		this.setAreaX(areaX);
		this.setAreaY(areaY);
		this.setState(state);
	}
	
	@Override
	public void update(DeltaState deltaState) {
		SoccerField field = this.getScene().getField();
		this.getRelativePosition().setX(field.getX() + this.getInitialPosition().getX() - MatchScene.SOCCER_FIELD_INITIAL_POSITION_X);
		this.getRelativePosition().setY(field.getY() + this.getInitialPosition().getY() - MatchScene.SOCCER_FIELD_INITIAL_POSITION_Y);
		super.update(deltaState);
	}
	
	public boolean isOutOfHisArea(SoccerBall ball) {
		return this.getX() < this.getAreaX().getBegin() || this.getX() > this.getAreaX().getEnd()
				|| this.getY() < this.getAreaY().getBegin() || this.getY() > this.getAreaY().getEnd();
	}
	
	public void resetCounter() {
		this.setRefreshCounter(40);
	}
	
	
	
	
	
	
	public int getRefreshCounter() {
		return refreshCounter;
	}

	public void setRefreshCounter(int counter) {
		this.refreshCounter = counter;
	}

	public Range getAreaX() {
		return areaX;
	}

	public void setAreaX(Range areaX) {
		this.areaX = areaX;
	}

	public Range getAreaY() {
		return areaY;
	}

	public void setAreaY(Range areaY) {
		this.areaY = areaY;
	}

	public Position getInitialPosition() {
		return initialPosition;
	}

	public void setInitialPosition(Position position) {
		this.initialPosition = position;
	}

	public Position getRelativePosition() {
		return relativePosition;
	}

	public void setRelativePosition(Position relativePosition) {
		this.relativePosition = relativePosition;
	}

}
